Jupyter at Bryn Mawr College |
|||
Public notebooks: /services/public/dblank / Experiments |
Requires:
Both can be installed via pip. These are already installed on Athena at Bryn Mawr College.
For the %%brain magic, you need to use the calysto magics:
from calysto import register_ipython_magics
register_ipython_magics()
These are already loaded locally on the Athena server.
You can also program the simulator without the magic, but it requires some boiler-plate code.
The simulator runs in a thread and has a GUI via the IPython widgets:
from calysto.simulation import View
View("Bug1")
You won't be able to see the simulation view above, unless you are running a live kernel. But it would look something like this:
Animated:
Each robot/agent also runs in a thread. You can easily create a thread (with any error messages going to the simulator above) using the %%brain magic:
%%brain
robot.forward(4)
robot.sleep(7.5)
robot.turnLeft(4.4)
robot.forward(2)
robot.turnRight(4.4)
The following methods on robot are defined:
Senses:
You can define a simulation file like Bug1.py:
from calysto.simulation import LadyBug, Spider, Simulation, Color
import math
def makeSimulation():
ladybug = LadyBug(550, 350, -math.pi/2)
spider = Spider(50, 50, 0)
def spiderBrain():
direction = 1
while simulation.is_running.is_set():
if spider.stalled:
direction = direction * -1
if direction == 1:
spider.forward(1)
else:
spider.backward(1)
spider.stop()
spider.brain = spiderBrain
simulation = Simulation(600, 400, ladybug, spider)
simulation.makeWall(500, 100, 10, 200, Color(255, 255, 0))
simulation.makeWall(10, 100, 190, 10, Color(255, 255, 0))
simulation.makeWall(300, 100, 200, 10, Color(255, 255, 0))
simulation.makeWall(100, 300, 410, 10, Color(255, 255, 0))
simulation.makeWall(10, 200, 390, 10, Color(255, 255, 0))
return simulation
There are three robots types:
Some effort has been taken to reduce the load on the server, and between notebook and kernel.
You can use the simulator in a variety of styles, including without graphics, faster than real time, multiple controllers, etc.
Here is an example getting an image from the LadyBug's camera:
from calysto.simulation import get_robot
from calysto.display import display
with get_robot() as robot:
display(robot.takePicture())